package de.sup.scs.prototyp.client.ui.graphic.walmdach;

import com.google.gwt.dom.client.Style;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;
import de.sup.scs.prototyp.client.ui.graphic.pultdach.GraphicPDPresenter;

public class GraphicWDView extends ViewImpl implements GraphicWDPresenter.MyView {

    @UiField
    LayoutPanel panel;

    private Widget toolbox;

    public interface MyUiBinder extends UiBinder<Widget, GraphicWDView> {}

    @Inject
    public GraphicWDView(final MyUiBinder binder, Widget toolbox){
        this.toolbox = toolbox;
        binder.createAndBindUi(this);
    }

    @Override
    public void setInSlot(Object slot, Widget content){

        if (slot.equals(GraphicWDPresenter.TOOLBOX)){

            if (toolbox != null){
                toolbox.removeFromParent();

            }
            panel.add(content);
            panel.setWidgetLeftWidth(content, 10, Style.Unit.PX,  300, Style.Unit.PX);
            panel.setWidgetTopHeight(content, 25, Style.Unit.PX, 500, Style.Unit.PX);

            toolbox = content;
        }
    }

    @Override
    public Widget asWidget() {
        return panel;
    }
}
